
package com.keycloak.admin.controller;

import com.keycloak.admin.model.params.AccessTokensParams;
import com.keycloak.admin.model.params.GetClientTokenParams;
import com.keycloak.admin.model.params.PhoneParams;
import com.keycloak.admin.model.params.ReturnParams;
import com.keycloak.admin.services.PassengerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import kong.unirest.HttpResponse;
import kong.unirest.JsonNode;
import kong.unirest.Unirest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/passenger")
@Api(value = "", tags = "2. passenger-Api", description = "API")
public class PassengerController {

    private Unirest unirest =new Unirest();

    @Autowired
    PassengerInfoService passengerInfoService;

    @ApiOperation(value = "openId登录", notes = "", httpMethod = "POST")
    @PostMapping("/openidLogin")
    public ReturnParams getClientToken(@RequestBody PhoneParams request) {
       return passengerInfoService.openIdLogin(request,"passenger");
    }


    /*@ApiOperation(value = "kong包测试", notes = "", httpMethod = "POST")
    @PostMapping("/test1")
    public  com.alibaba.fastjson.JSONObject test1(@RequestBody AccessTokensParams accessTokensParams) {

        try {
            HttpResponse<JsonNode> response = unirest.post("https://keycloak.dev.yuedaowang.com/auth/realms/yuedao-dev/protocol/openid-connect/token/introspect")
                    .header("Content-Type", "application/x-www-form-urlencoded")
                    .field("client_id", "driver")
                    .field("client_secret",  "b279a201-225c-4349-8e5e-283cece51ee1")
                    .field("token", accessTokensParams.getToken())
                    .asJson();

            com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response.getBody().toString());
            return jsonObject;

        }catch (Exception e){
            e.printStackTrace();
            return null;
        }finally {
        }

    }*/



}

